package com.lalameow.packet.packImpl;

import com.lalameow.packet.BasePack;
import com.lalameow.packet.enumtype.PackType;
import com.lalameow.packet.enumtype.VailPlayerState;
import com.lalameow.packet.pojo.AuthenticateClient;
import com.lalameow.serverlogingate.network.ClientManager;
import io.netty.channel.ChannelHandlerContext;
import lombok.Data;

/**
 * Created with IntelliJ IDEA.
 * 创建人: 陈刚
 * 日期: 2018/5/11
 * 时间: 9:59
 * 功能：请进行修改
 */
@Data
public class VaildPlayerPack extends PacketAbstract {
    private String playerName;
    @Override
    public BasePack revice(ChannelHandlerContext ctx) {
        BasePack basePack=new BasePack();
        basePack.setPackType(PackType.VAILDPLAYERRECIVEPACK);
        VaildPlayerRecivePack vaildPlayerRecivePack=new VaildPlayerRecivePack();
        VailPlayerState vailPlayerState=ClientManager.instanss.getPlayerCache().getIfPresent(this.playerName.trim());
        if(vailPlayerState!=null){
            vaildPlayerRecivePack.setPlayerName(playerName.trim());
            vaildPlayerRecivePack.setVailPlayerState(vailPlayerState);
            ClientManager.instanss.getPlayerCache().invalidate(playerName.trim());
        }else {
            vaildPlayerRecivePack.setPlayerName(playerName.trim());
            vaildPlayerRecivePack.setVailPlayerState(VailPlayerState.NOLOGIN);
        }
        basePack.setBodyContent(vaildPlayerRecivePack.toJsonStr());
        return basePack;
    }
}
